<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加员工</title>
    <style>
        .form-container { width: 500px; margin: 20px auto; }
        .error { color: red; }
        label { display: inline-block; width: 100px; }
        input { margin-bottom: 10px; width: 300px; padding: 5px; }
        .header { text-align: center; margin: 20px; }
        button { margin-right: 10px; padding: 5px 15px; }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(function() {
            $("form").submit(function() {
                // 姓名验证
                if ($("input[name='name']").val().trim() === "") {
                    alert("姓名不能为空");
                    return false;
                }
                // 薪资验证
                if (isNaN($("input[name='salary']").val()) || parseFloat($("input[name='salary']").val()) <= 0) {
                    alert("薪资必须为正数");
                    return false;
                }
                return true;
            });
        });
    </script>
</head>
<body>
<div class="header">
    <h1>添加新员工</h1>
    <a href="${pageContext.request.contextPath}/employee/list">返回列表</a>
    <a href="${pageContext.request.contextPath}/logout">退出登录</a>
</div>

<div class="form-container">
    <form action="${pageContext.request.contextPath}/employee/add" method="post">
        <div>
            <label>姓名:</label>
            <input type="text" name="name" required>
        </div>
        <div>
            <label>部门:</label>
            <input type="text" name="department" required>
        </div>
        <div>
            <label>职位:</label>
            <input type="text" name="position" required>
        </div>
        <div>
            <label>薪资:</label>
            <input type="number" step="0.01" name="salary" required>
        </div>
        <div>
            <label>邮箱:</label>
            <input type="email" name="email">
        </div>
        <div>
            <label>电话:</label>
            <input type="tel" name="phone">
        </div>
        <div>
            <label>入职日期:</label>
            <input type="date" name="hireDate" required>
        </div>
        <div class="error">${error}</div>
        <div>
            <button type="submit">提交</button>
            <button type="reset">重置</button>
        </div>
    </form>
</div>
</body>
</html>